package com.cyq.dascma.exception;


import com.cyq.dascma.result.Result;
import com.cyq.dascma.result.ResultGenerator;

/**
 * 服务异常
 * dingwen
 * 2021/3/9 17:43
 **/
public class ServiceException extends RuntimeException {
    private static final long serialVersionUID = 1L;

    private Result result;


    public Result result() {
        return result;
    }

    public ServiceException(Result r) {
        super(r.getMessage());
        this.result = r;
    }

    public ServiceException(Result r, Throwable cause) {
        super(r.getMessage(), cause);
        this.result = r;
    }

    public ServiceException(String... msg) {
        StringBuilder stringBuffer = new StringBuilder();
        if (msg != null) {
            for (String s : msg) {
                stringBuffer.append(s);
            }
        }
        String m = stringBuffer.toString();
        result = ResultGenerator.genFailureResult(m);
    }

    public ServiceException(Throwable cause) {
        super(cause);
    }

    public ServiceException(String message, Throwable cause) {
        super(message, cause);
        result = ResultGenerator.genFailureResult(message);
    }

    @Override
    public String getMessage() {
        return this.result.toString();
    }

}
